import request from '@/utils/request'

export function get(dictName) {
  const params = {
    dictName,
    page: 0,
    size: 9999
  }
  return request({
    url: 'api/dictDetail',
    method: 'get',
    params
  })
}

export function getDictDetails(dictName) {
  const params = {
    dictName,
    page: 0,
    size: 9999
  }
  return request({
    url: 'api/dictDetail',
    method: 'get',
    params
  })
}

export function dictDetailAdd(data) {
  return request({
    url: 'api/dictDetail',
    method: 'post',
    data
  })
}

export function add(data) {
  return request({
    url: 'api/dictDetail',
    method: 'post',
    data
  })
}

export function del(id) {
  return request({
    url: 'api/dictDetail/' + id,
    method: 'delete'
  })
}

export function edit(data) {
  return request({
    url: 'api/dictDetail',
    method: 'put',
    data
  })
}

export function getDictLabel(id, dictDetail) {
  for (var index in dictDetail) {
    const obj = dictDetail[index]
    if (obj.value === id) {
      return obj.label
    }
  }
  return id
}

export function byDictId(id) {
  return request({
    url: 'api/dictDetail/findByDeptId/' + id,
    method: 'get'
  })
}

// 新增巡检模板，获取类型、对象、项目树形数据
export function getInspectionTree(id) {
  return request({
    url: 'api/dictDetail/inspectiontree',
    method: 'get'
  })
}
